#include "iotgo.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "custom_data_type.h"


void *updateDemoThread(void *arg)
{
    static unsigned char count = 0;
    UPDATE_CLOUD_RESULT result;
    memset(&result,0,sizeof(result));
//    printf("updateDemoThread!!!!!\n");
    sleep(10);
    memcpy(result.bucketName,"zhao wei",9);
    memcpy(result.filePath,"zhao wei",9);
    memcpy(result.sign,"zhao wei",9);
    memcpy(result.eventid,"20160921103300",15);
    iotgoUpdateCloudStoreDone(&result);
    while(1)
    {
//	iotgoUpdateP2Ppassword("mechineID", "p2pID", "password");
//	iotgoUpdateWifiRssi(90);

	
	count++;
	if(count == 5)
	{
	    pthread_exit((void *)0);
	}
	sleep(3);
    }
}


int main(void)
{
    int32_t ret;
    uint8_t buf[501];
    int32_t fd = 0;
    pthread_t update_demo_thread;
    //ret = configWithApp(60);
    ret = iotgoConnect();
    ret = pthread_create(&update_demo_thread, NULL ,updateDemoThread,NULL); 

    printf("[%s] iotgoConnect ret is %d\n",__FUNCTION__,ret);
    memset(buf,0,501);
    while(1)
    {
	ret = 0;
//	ret = iotgoRead(fd,buf,500);
	if(ret > 0)
	{
	    printf("\nread from app:\n");
	    printf("%s\n",buf);
	    iotgoWrite(fd,buf,strlen(buf));
	}
	sleep(1);
	memset(buf,0,501);
    }
    return 0;
}
